﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SpotsHub.Tools.MassUploader.Forms
{
    public partial class PictureReview : Form
    {
        private int start = 0;

        public List<string> PictureFiles;

        public PictureReview()
        {
            InitializeComponent();
        }

        private void PictureReview_Load(object sender, EventArgs e)
        {
            start = 0;
            loadPicture();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (start >= 8)
            {
                start -= 8;
                loadPicture();
            }
        }

        private void loadPicture()
        {
            var ps = PictureFiles.ToArray();

            var pbs = new PictureBox[8];
            pbs[0] = pictureBox1;
            pbs[1] = pictureBox2;
            pbs[2] = pictureBox3;
            pbs[3] = pictureBox4;
            pbs[4] = pictureBox5;
            pbs[5] = pictureBox6;
            pbs[6] = pictureBox7;
            pbs[7] = pictureBox8;

            var tbs = new TextBox[8];
            tbs[0] = textBox1;
            tbs[1] = textBox2;
            tbs[2] = textBox3;
            tbs[3] = textBox4;
            tbs[4] = textBox5;
            tbs[5] = textBox6;
            tbs[6] = textBox7;
            tbs[7] = textBox8;

            int i;

            for (i = 0; i < 8; i++)
            {
                pbs[i].Visible = false;
                tbs[i].Enabled = false;
                tbs[i].Text = "";
            }

            for (i = 0; i < 8; i++)
            {
                if (i + start < ps.Length)
                {
                    tbs[i].Text = i.ToString();
                    pbs[i].Load(ps[start + i]);
                    pbs[i].Visible = true;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (start + 8 <= PictureFiles.Count / 8 * 8)
            {
                start += 8;
                loadPicture();
            }
        }

        private void openPicture(string location)
        {
            string args = string.Format("/Select, {0}", location);

            var pfi = new System.Diagnostics.ProcessStartInfo("Explorer.exe", args);
            System.Diagnostics.Process.Start(pfi);
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox1.ImageLocation);
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox5.ImageLocation);
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox6.ImageLocation);
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox2.ImageLocation);
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox3.ImageLocation);
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox4.ImageLocation);
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox8.ImageLocation);
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            openPicture(pictureBox7.ImageLocation);
        }
    }
}
